% GAUTIER LE BIHAN - 2020
% Replication files for "Shocks vs Menu Costs: Patterns of Price Rigidity in an Estimated Multi-Sector Menu-Cost Model?" Review of Economics and Statistics
%
% This code produces Figure 3 & 4 � Appendix Figure L

clear all
clear matrix
clc

cd  ..\..\Simulations_VC\MS_produits_CPlus


load  ..\..\Estimation_param\MS_produits_CPlus\actual_moments_k
weight=actual_moments_k(:,12);
sum(weight)

load  ..\..\Simulations_VC\MS_produits_CPlus\stat_d
param=stat_d;

weight=actual_moments_k(:,12);
sum(weight)
p0=param(:,1);
mu_c=param(:,2);
sig_a=param(:,3);
rho_a=param(:,4);

param0=[p0 mu_c sig_a rho_a]

secteur=actual_moments_k(:,1);

f=param(:,5);
muc=param(:,2);
f_p=param(:,6);
med=param(:,7);
interq=param(:,8);
kur=param(:,9);
q1=param(:,10);
q2=param(:,11);
q3=param(:,12);

moments_sim=[f f_p med interq kur]
moments_actual=[actual_moments_k(:,2:6)]

sum(weight)


param=[p0 mu_c sig_a rho_a];
wmed=ones(1,size(param,2)+2);
v=size(param,1);
weight_tot=weight;

max_freq=0.22;
 max_p0=0.16;
max_muc=0.2;%max(mu_c);
max_siga=0.12;%max(sig_a);
min_rhoa=0.4;
max_rhoa=0.9;

max_muc=0.18;%max(mu_c);
max_siga=0.12;%max(sig_a);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SCATTER FREQUENCY   ******************/

 freq=moments_actual(:,1);
y=freq((freq<max_freq),:);
sz=weight((freq<max_freq),:)*150;
figure(1);
%P0
x=p0((freq<max_freq),:);
subplot(2,3,1);
%scatter(x, y,sz);
scatter(x,y,'x', 'k')
lsline
axis([0 max_p0 0 max_freq])
xlabel('\lambda') % x-axis label
ylabel('Freq.') % y-axis label


%MU_c
subplot(2,3,2);
x=mu_c((freq<max_freq),:);
%scatter(x, y,sz); 
scatter(x,y,'x', 'k')
lsline
axis([0 max_muc 0 max_freq])
xlabel('\mu') % x-axis label
ylabel('Freq.') % y-axis label

%sig_a
subplot(2,3,3);
x=sig_a((freq<max_freq),:);

scatter(x,y,'x', 'k')
lsline
axis([0 max_siga 0 max_freq])
xlabel('\sigma') % x-axis label
ylabel('Freq.') % y-axis label

x1=p0((freq<max_freq),:);
x2=mu_c((freq<max_freq),:);
x3=sig_a((freq<max_freq),:);
x4=rho_a((freq<max_freq),:);
[b,bint] = regress(y,[ones(size(x1)) x1 x2 x3 x4])
b 
bint
lm = fitlm([x1 x2 x3 x4],y,'linear')


%%%%%%%%%%%%%%%%%%%%%%%SHARE OF INCREASES%%%%%%%%%%%%%%%
min_freq=0.3;
freq=moments_actual(:,2);;
y=freq(freq>min_freq,:);
max_freq=1;
sz=weight((freq>min_freq),:)*150;


%figure(2);
%P0
x=p0(freq>min_freq,:);
subplot(2,3,4);
scatter(x,y,'x', 'k')
lsline
axis([0 max_p0 min_freq max_freq])
xlabel('\lambda') % x-axis label
ylabel('Frac. increases') % y-axis label

%MU_c
subplot(2,3,5);
x=mu_c(freq>min_freq,:);
scatter(x,y,'x', 'k')
lsline
axis([0 max_muc min_freq max_freq])
xlabel('\mu') % x-axis label
ylabel('Frac. increases') % y-axis label

%sig_a
subplot(2,3,6);
x=sig_a(freq>min_freq,:);
scatter(x,y,'x', 'k')
lsline
axis([0 max_siga min_freq max_freq])
xlabel('\sigma') % x-axis label
ylabel('Frac. increases') % y-axis label


print(' ..\..\..\figures\figure4.pdf','-dpdf', '-fillpage')
print(' ..\..\..\figures\figure4','-depsc')

x1=p0((freq>min_freq),:);
x2=mu_c((freq>min_freq),:);
x3=sig_a((freq>min_freq),:);
x4=rho_a((freq>min_freq),:);
[b,bint] = regress(y,[ones(size(x1)) x1 x2 x3 x4])
%b 
%bint
%lm = fitlm([x1 x2 x3 x4],y,'linear')
mdl = LinearModel.fit([x1 x2 x3 x4],y,'linear','Weights',sz)
%%%%%%%%%%%%%%%%%%%%%%%MEDIAN%%%%%%%%%%%%%%%
min_freq=0;
max_freq=0.14;
freq=moments_actual(:,3);
y=freq(freq<max_freq,:);
sz=weight(freq<max_freq,:)*150;

figure(2);
%P0
x=p0(freq<max_freq,:);
subplot(3,3,1);
scatter(x,y,'x', 'k')
lsline
% hold on;
% linearCoefficients = polyfit(x, y, 2)
% xFit = linspace(0,max_p0, 50);
% yFit = polyval(linearCoefficients, xFit);
% plot(xFit, yFit, '-');
axis([0 max_p0 min_freq max_freq])
xlabel('\lambda') % x-axis label
ylabel('Median') % y-axis label

%MU_c
subplot(3,3,2);
x=mu_c(freq<max_freq,:);
%scatter(x, y,sz);
scatter(x,y,'x', 'k')
lsline
axis([0 max_muc min_freq max_freq])
xlabel('\mu') % x-axis label
ylabel('Median') % y-axis label

%sig_a
subplot(3,3,3);

x=sig_a(freq<max_freq,:);
%scatter(x, y,sz);
scatter(x,y,'x', 'k')
lsline
axis([0 max_siga min_freq max_freq])
xlabel('\sigma') % x-axis label
ylabel('Median') % y-axis label


x1=p0((freq<max_freq),:);
x2=mu_c((freq<max_freq),:);
x3=sig_a((freq<max_freq),:);
x4=rho_a((freq<max_freq),:);
[b,bint] = regress(y,[ones(size(x1)) x1 x2 x3 x4])
b 
bint
lm = fitlm([x1 x2 x3 x4],y,'linear')

%%%%%%%%%%%%%%%%%%%%%%%INTERQUARTILE%%%%%%%%%%%%%%%
min_freq=0;
max_freq=0.25;
freq=moments_actual(:,4);
y=freq(freq<max_freq,:);
sz=weight(freq<max_freq,:)*150;

%figure(4);
%P0
x=p0(freq<max_freq,:);
subplot(3,3,4);
scatter(x,y,'x', 'k')
lsline
axis([0 max_p0 min_freq max_freq])
xlabel('\lambda') % x-axis label
ylabel('Interquartile') % y-axis label

%MU_c
subplot(3,3,5);

x=mu_c(freq<max_freq,:);
%scatter(x, y,sz); 
scatter(x,y,'x', 'k')
lsline
axis([0 max_muc min_freq max_freq])
xlabel('\mu') % x-axis label
ylabel('Interquartile') % y-axis label

%sig_a
subplot(3,3,6);

x=sig_a(freq<max_freq,:);
%scatter(x, y,sz); 
scatter(x,y,'x', 'k')
lsline
axis([0 max_siga min_freq max_freq])
xlabel('\sigma') % x-axis label
ylabel('Interquartile') % y-axis label

 %print('h:\8_Gautier_Le_Bihan\PAPER_DRAFT\figures\scatter_idp.pdf','-dpdf')
 %print('h:\8_Gautier_Le_Bihan\PAPER_DRAFT\figures\scatter_idp','-depsc')


x1=p0((freq<max_freq),:);
x2=mu_c((freq<max_freq),:);
x3=sig_a((freq<max_freq),:);
x4=rho_a((freq<max_freq),:);
[b,bint] = regress(y,[ones(size(x1)) x1 x2 x3 x4])
b 
bint

lm = fitlm([x1 x2 x3 x4],y,'linear')


%%%%%%%%%%%%%%%%%%%%%%%KURTOSIS%%%%%%%%%%%%%%%
min_freq=2;
max_freq=12;
freq=moments_actual(:,5);
y=freq(freq<max_freq,:);
sz=weight(freq<max_freq,:)*150;

%figure(5);
%P0
x=p0(freq<max_freq,:);
subplot(3,3,7);

%scatter(x, y,sz);
scatter(x,y,'x', 'k')
lsline
axis([0 max_p0 min_freq max_freq])
xlabel('\lambda') % x-axis label
ylabel('Kurtosis') % y-axis label

%MU_c
subplot(3,3,8);

x=mu_c(freq<max_freq,:);
%scatter(x, y,sz); 
scatter(x,y,'x', 'k')
lsline

axis([0 max_muc min_freq max_freq])
xlabel('\mu') % x-axis label
ylabel('Kurtosis') % y-axis label

%sig_a
subplot(3,3,9);
x=sig_a(freq<max_freq,:);
%scatter(x, y,sz);
scatter(x,y,'x', 'k')
lsline

axis([0 max_siga min_freq max_freq])
xlabel('\sigma') % x-axis label
ylabel('Kurtosis') % y-axis label


print(' ..\..\..\figures\figure5.pdf','-dpdf', '-fillpage')
print(' ..\..\..\figures\figure5','-depsc')

x1=p0((freq<max_freq),:);
x2=mu_c((freq<max_freq),:);
x3=sig_a((freq<max_freq),:);
x4=rho_a((freq<max_freq),:);
[b,bint] = regress(y,[ones(size(x1)) x1 x2 x3 x4])
b 
bint

lm = fitlm([x1 x2 x3 x4],y,'linear')


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SCATTER PARAM   ******************/
max_freq=0.25
freq=moments_actual(:,1);
y=freq((freq<max_freq),:);

figure(6);
%P0
x=p0(freq<max_freq,:);
y=mu_c(freq<max_freq,:);
subplot(3,1,1);
scatter(x,y,'x', 'k')
lsline

axis([0 max_p0 0 max_muc])
xlabel('\lambda') % x-axis label
ylabel('\mu') % y-axis label
pbaspect([1 1 1])

%MU_c
subplot(3,1,2);
x=p0((freq<max_freq),:);
y=sig_a((freq<max_freq),:);
scatter(x,y,'x', 'k')
lsline
axis([0 max_p0 0 max_siga])
xlabel('\lambda') % x-axis label
ylabel('\sigma') % y-axis label
pbaspect([1 1 1])


subplot(3,1,3);
x=mu_c((freq<max_freq),:);
y=sig_a((freq<max_freq),:);
scatter(x,y,'x', 'k')
lsline
axis([0 max_muc 0 max_siga])
xlabel('\mu') % x-axis label
ylabel('\sigma') % y-axis label

%HLB
pbaspect([1 1 1])
print(' ..\..\..\figures\scatter_param.pdf','-dpdf','-fillpage')
print(' ..\..\..\figures\scatter_param','-depsc')






